home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_12_08 / plauger / isxlong.c < prev    next >
C/C++ Source or Header  |  1994-06-09  |  569b  |  28 lines

  1. -------------------------- Listing 6: long integer extractor  ---------
  2.  
  3. // isxlong -- istream::operator>>(long&)
  4. #include <errno.h>
  5. #include <stdlib.h>
  6. #include <istream>
  7.  
  8. istream& istream::operator>>(long& lo)
  9.     {    // extract a long
  10.     _TRY_IO_BEGIN
  11.     if (!ipfx())
  12.         setstate(failbit);
  13.     else
  14.         {    // gather characters and convert
  15.         char ac[_MAX_INT_DIG];
  16.         char *ep;
  17.         errno = 0;
  18.         const long x = strtol(ac, &ep, _Getifld(ac));
  19.         if (ep == ac || errno != 0)
  20.             setstate(failbit);
  21.         else
  22.             lo = x;
  23.         }
  24.     isfx();
  25.     _CATCH_IO_END
  26.     return (*this);
  27.     }
  28.